<{include file="public/header.html"}> 
	<header>
		<div class="title title-border-sm bj-white">
			<a href="javascript:history.go(-1);" class="icon-return iconfont title-left title-top col-red">&#xe604;</a>
			<h1 class="text-center name">重置密码</h1>
		</div>
	</header>
	<form class="plr10" id="form-reset" action="" data-href="" onsubmit="return false;">
		<div class="input-group input-group-70">
			<input type="password" name="newPass" id="newPass" placeholder="6-16位密码，由数字+字母组成，区分大小写" oninput="if(value.length>16)value=value.slice(0,16)" data-validate="pwd" data-describedby="pwd-description" />
		</div>
		<div class="input-group input-group-70">
			<input type="password" name="renewPass" id="renewPass" placeholder="确认新登录密码" oninput="if(value.length>16)value=value.slice(0,16)"/>
		</div>
                <input type="submit" class="btn btn-yes mt10" id="form-reset-btn" value="确 认" />
	</form>
<script type="text/javascript">
$(function(){
    var check_flag = true,check_count = 0;
    $.mvalidateExtend({
        pwd:{
            required : true,   
            pattern : /^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z]{1}[0-9A-Za-z]{5,16}$/,
            each:function(){

            },
            descriptions:{
                required : '<div class="field-invalidmsg">请输入新密码</div>',
                pattern : '<div class="field-invalidmsg">6-16位密码，由数字+字母组成，区分大小写</div>',
            }
        }
    });
     $("#form-reset").mvalidate({
        type:1,
        onKeyup:true,
        sendForm:true,
        firstInvalidFocus:false,
        descriptions: {
        },
        valid:function(event,options){
            if($("#renewPass").val() != $("#newPass").val()){
                $.mvalidateTip("两次输入的密码不一致");return false;
            }
            add_check_oper_listener();
            var url = $('#form-reset').attr("data-href");
            check_flag = false;
            $("#form-reset-btn").val("设置中...");
            $.ajax({
                type: "POST",
                url: url,
                async:true, 
                data: 'newPass=' + $('#newPass').val(),
                success: function(resp) {
                    resp = $.parseJSON(resp);
                    if(resp.reqStatus){
                        $.mvalidateTip("密码设置成功,2s后自动返回登录页面");
                        $("#form-reset-btn").val("设置成功");
                        $("#newPass").val("");$("#renewPass").val("");
                        setTimeout(function(){
                            window.location.href = resp.url;
                        },1500);
                    }else{
                        cancel_check_oper_listener();
                        $("#form-reset-btn").val("重新设置");
                        $.mvalidateTip(resp.errorMsg);
                        return false;
                    }
                }
            });
        },
        invalid:function(event, status, options){
            //点击提交按钮时,表单未通过验证触发函数
        },
        eachField:function(event,status,options){
            //点击提交按钮时,表单每个输入域触发这个函数 this 执向当前表单输入域，是jquery对象
        },
        eachValidField:function(val){},
        eachInvalidField:function(event, status, options){},
    })
    
    function add_check_oper_listener(){
        if(check_count == 2){
            check_count = 0;
            $.mvalidateTip("操作过于频繁");return false;
        }
        if(!check_flag){
            check_count ++;
            $.mvalidateTip("正在处理重置操作");return false;
        }
    };
    function cancel_check_oper_listener(){
        check_count = 0;
        check_flag = true;
    }
});
</script>
<{include file="public/footer.html"}> 